package com.autumn.zero.authorization.constants;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.autumn.common.api.domain.values.IntegerConstantItemValue;

/**
 * 登录结果
 * 
 * @author 杨昌国 2018-11-29 22:48:52
 */
public final class LoginResultConstants implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4451159849971016387L;

	/**
	 * 成功
	 */
	public static final int SUCCESS = 1;

	/**
	 * 无效的用户账户
	 */
	public static final int INVALID_USER_ACCOUNT = 2;

	/**
	 * 无效的密码
	 */
	public static final int INVALID_PASSWORD = 3;

	/**
	 * 无效的用户账户或密码
	 */
	public static final int INVALID_USER_ACCOUNT_OR_PASSWORD = 4;

	/**
	 * 未激活
	 */
	public static final int NOT_ACTIVATE = 5;

	/**
	 * 无效的第三方提供程序序
	 */
	public static final int INVALID_EXTERNAL_PROVIDER = 6;

	/**
	 * 账户锁定
	 */
	public static final int ACCOUNT_LOCKING = 7;

	/**
	 * 账户过期
	 */
	public static final int ACCOUNT_EXPIRED = 8;

	private static final Map<Integer, IntegerConstantItemValue> NAME_MAP = new HashMap<>();

	static {
		NAME_MAP.put(SUCCESS, new IntegerConstantItemValue(SUCCESS, "成功", ""));
		NAME_MAP.put(INVALID_USER_ACCOUNT, new IntegerConstantItemValue(INVALID_USER_ACCOUNT, "无效的用户账户", ""));
		NAME_MAP.put(INVALID_PASSWORD, new IntegerConstantItemValue(INVALID_PASSWORD, "无效的密码", ""));
		NAME_MAP.put(INVALID_USER_ACCOUNT_OR_PASSWORD,
				new IntegerConstantItemValue(INVALID_USER_ACCOUNT_OR_PASSWORD, "无效的用户账户或密码", ""));
		NAME_MAP.put(NOT_ACTIVATE, new IntegerConstantItemValue(NOT_ACTIVATE, "账户未激活", ""));
		NAME_MAP.put(INVALID_EXTERNAL_PROVIDER,
				new IntegerConstantItemValue(INVALID_EXTERNAL_PROVIDER, "无效的第三方提供程序", ""));
		NAME_MAP.put(ACCOUNT_LOCKING, new IntegerConstantItemValue(ACCOUNT_LOCKING, "账户锁定", ""));
		NAME_MAP.put(ACCOUNT_EXPIRED, new IntegerConstantItemValue(ACCOUNT_EXPIRED, "账户过期", ""));
	}

	/**
	 * 是否存在
	 * 
	 * @param value 值
	 * @return
	 */
	public static boolean exist(Integer value) {
		if (value == null) {
			return false;
		}
		return NAME_MAP.containsKey(value);
	}

	/**
	 * 获取名称
	 * 
	 * @param value 值
	 * @return
	 */
	public static String getName(Integer value) {
		IntegerConstantItemValue item = NAME_MAP.get(value);
		if (item == null) {
			return "";
		}
		return item.getName();
	}

	/**
	 * 项目集合
	 * 
	 * @return
	 */
	public static Collection<IntegerConstantItemValue> items() {
		return NAME_MAP.values();
	}
}
